﻿Imports System.IO
Public Class frmEditServers
    'Dim dsServerList As New DataSet
    Dim dtServerList As New DataSet
    Dim FileLocation As String = Form1.FileLocation

    Private Sub frmEditServers_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If Me.DialogResult = Windows.Forms.DialogResult.OK Then
            dtServerList.WriteXml(FileLocation)
            Form1.dtServerList = dtServerList
        ElseIf Me.DialogResult = Windows.Forms.DialogResult.Abort Then
            'do nothing and let it close
        Else
            If MsgBox("Do you wish to save any changes?", MsgBoxStyle.YesNo, "Save Changes") = MsgBoxResult.Yes Then
                dtServerList.WriteXml(FileLocation)
                Form1.dtServerList = dtServerList
                Me.DialogResult = Windows.Forms.DialogResult.OK
            Else
                Me.DialogResult = Windows.Forms.DialogResult.Cancel
            End If
        End If

    End Sub

    Private Sub frmEditServers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Try
            'Dim FileLocation As String = Application.StartupPath & "\servers.xml"
            If File.Exists(FileLocation) Then
                'dsServerList.ReadXml(Application.StartupPath & "servers.xml")
                dtServerList.ReadXml(FileLocation)
                If dtServerList.Tables.Count = 0 Then
                    MakeTable()
                ElseIf dtServerList.Tables(0).Rows.Count = 0 Then
                    MakeTable()
                End If
            Else
                MakeTable()
            End If
            DataGridView1.DataSource = dtServerList.Tables(0)
            DataGridView1.Refresh()


        Catch ex As Exception

        End Try

    End Sub

    Private Sub MakeTable()
        Dim ds As New DataSet
        Dim dt As DataTable = New DataTable("Servers")
        dt.Columns.Add("Server Name", System.Type.GetType("System.String"))
        dt.Columns.Add("Web Service Location", System.Type.GetType("System.String"))
        'dt.Columns.Add("Program", System.Type.GetType("System.String"))
        dtServerList.Tables.Add(dt)
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Me.DialogResult = Windows.Forms.DialogResult.OK
        Me.Close()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        Me.DialogResult = Windows.Forms.DialogResult.Abort
    End Sub
End Class